﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcControlToolkit
{
    internal static class InternalExtensions
    {
        public static void AddRange(this IDictionary<string, object> dict, IDictionary<string, object> source)
        {
            foreach (KeyValuePair<string, object> pair in source)
                dict.Add(pair.Key, pair.Value);
        }

        public static void AddIfUnique(this IDictionary<string, object> dict, string key, object value)
        {
            if (!dict.ContainsKey(key))
                dict.Add(key, value);
        }

        public static void AddIfNotDefault(this IDictionary<string, object> dict, string key, int value)
        {
            if (value != default(int))
                dict.Add(key, value);
        }

        public static void AddIfNotDefault(this IDictionary<string, object> dict, string key, string value)
        {
            if (!string.IsNullOrEmpty(value))
                dict.Add(key, value);
        }

        public static void AddIfNotEqual(this IDictionary<string, object> dict, string key, object value, object compareTo)
        {
            if(!value.Equals(compareTo))
                dict.Add(key, value);
        }
    }
}
